﻿using System;
using BusinessObject;
using Model;

namespace ViewLayer.Pages.Releases
{
    public partial class CadastroRelease : System.Web.UI.Page
    {
        //private int i;
        private User user;

        private Project project;

        protected void Page_Load(object sender, EventArgs e)
        {
            user = (User)Session["User"];
            this.lblErro.Visible = false;

            if (user == null)
            {
                Response.Redirect("../Account/Login.aspx");
            }

            if (!IsPostBack)
            {
                if (Session["Project"] != null)
                {
                    this.project = (Project)Session["Project"];
                }
                //redireciona para a página de projetos
                else
                {
                    Response.Redirect("../Default.aspx");
                }
            }
        }

        protected void btnSalvar_Click(object sender, EventArgs e)
        {
            Project projeto = (Project)Session["Project"];

            var inicio = DateTime.Parse(this.txtDataInicio.Text);
            var termino = DateTime.Parse(this.txtDataTermino.Text);


            if (ReleaseBO.Instance.CheckDates(projeto, inicio, termino))
            {
                ReleaseBO.Instance.InsertRelease(projeto, this.txtName.Text,
                    inicio, termino);
                Response.Redirect("../Projetos/InicioProjeto.aspx");
            }
            else
            {
                this.lblErro.Visible = true;
            }
        }
    }
}